export class CountdownTimer {
  private targetTimestamp: number;

  constructor(targetTimestamp: number) {
    this.targetTimestamp = targetTimestamp;
  }

  startCountdown(): void {
    setInterval(() => {
      const currentTime = Date.now();
      const timeDifference = currentTime - this.targetTimestamp;

      if (timeDifference > 0) {
        const countdown = this.calculateCountdown(timeDifference);
        this.displayCountdown(countdown);
      } else {
        console.log("Countdown finished!");
      }
    }, 1000);
  }

  calculateCountdown(milliseconds: number): {
    hours: number;
    minutes: number;
    seconds: number;
  } {
    const seconds = Math.floor(milliseconds / 1000);
    const hours = Math.floor(seconds / 3600);
    const minutes = Math.floor((seconds % 3600) / 60);
    const remainingSeconds = seconds % 60;

    return { hours, minutes, seconds: remainingSeconds };
  }

  displayCountdown(countdown: {
    hours: number;
    minutes: number;
    seconds: number;
  }): void {
    console.log(
      `Time remaining: ${countdown.hours} hours ${countdown.minutes} minutes ${countdown.seconds} seconds`
    );
  }
}
